package com.yilin.tms.truck.controller;

import com.yilin.tms.core.application.ReturnData;
import com.yilin.tms.core.commons.annotation.UserTarget;
import com.yilin.tms.core.entity.data.statistics.VehicleNoAuthStatistics;
import com.yilin.tms.core.entity.data.statistics.truck.VehicleStatistics;
import com.yilin.tms.core.entity.user.UserType;
import com.yilin.tms.core.commons.base.BaseController;
import com.yilin.tms.truck.service.impl.TruckStatisticsService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/truck/statistics/")
public class StatisticsController extends BaseController {

    @Resource
    TruckStatisticsService statisticsService;

    /**
     * 统计不同状态的车辆
     */
    @PostMapping(value = "getVehicleByTruckStatus")
    public ReturnData<Map<String, Object>> getVehicleByTruckStatus() {
        Map<String, Object> vehicleByTruckStatus = statisticsService.getVehicleByTruckStatus();
        return jsonView(true, "获取成功", vehicleByTruckStatus);
    }

    /**
     * 获取车源统计数据
     */
    @PostMapping("getVehicleStatistics")
    public ReturnData<VehicleStatistics> getVehicleStatistics() {
        VehicleStatistics vehicleStatistics = statisticsService.getVehicleStatistics(getLoginUser());
        return jsonView(true, "获取成功", vehicleStatistics);
    }

    /**
     * 获取车辆证件待认证数据
     */
    @PostMapping(value = "getVehicleNoAuthStatistics")
    public ReturnData<VehicleNoAuthStatistics> getVehicleNoAuthStatistics() {
        VehicleNoAuthStatistics statistics = new VehicleNoAuthStatistics();
        statistics.setTransportLicense(statisticsService.getTransportLicenseNoAuthCount());
        statistics.setTravelLicense(statisticsService.getTravelLicenseNoAuthCount());
        if (statistics.getTransportLicense() == 0 && statistics.getTravelLicense() == 0){
            statistics.setAllEmpty(true);
        }
        return jsonView(true, "获取成功！", statistics);
    }

}
